package com.dd.controller;

import com.dd.common.aop.annation.Login;
import com.dd.common.response.Result;
import com.dd.common.utils.HttpUtils;
import com.dd.pojo.entry.Folder;
import com.dd.pojo.entry.UserFoldFile;
import com.dd.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
@RequiredArgsConstructor
@Api(tags = "文件查询接口")
public class SearchFileFolderController {
    private final SearchService searchService;
    @PostMapping("/search_file_floder_data/{filename}")
    @ApiOperation("查询文件/文件夹数据")
    @Login
    public Result<?> searchFileFloder(@PathVariable("filename") String filename, HttpServletRequest request){
        String id = HttpUtils.anasyUserId(request);
        List<UserFoldFile> userFoldFiles = searchService.SearchFiles(id, filename);
        List<Folder> folders = searchService.SearchFolder(id,filename);
        Map<String,Object> map = new HashMap<>();
        map.put("folders",folders);
        map.put("files",userFoldFiles);
        return Result.success(map);
    }
}
